import Utils from '../index';
import adapter from './adapter';
import getPluginType from './getPluginType';
import configJson from '../../../pluginTemp/config.json';
import information from '../../../scripts/information.json';

const setAttributes = (dom, props) => {
  const pluginType = getPluginType();
  const newProps = adapter(props, pluginType);
  const { customConfig = {}, type = '' } = newProps;
  const requirementNum = configJson['requirement-number']
    ? `${configJson['requirement-number']}-`
    : '';
  const domSymbol = customConfig?.id
    ? `${pluginType}-${type}-secondary-${requirementNum}${customConfig.id}`
    : `${pluginType}-${type}-secondary-${requirementNum}${Utils.generateUUID()}`;
  const developers = information.developers || '';
  let className = dom?.className;
  className = className ? `${className} ${domSymbol}` : domSymbol;
  dom?.setAttribute('class', className);
  dom?.setAttribute('developers', developers);
  if (import.meta.env.PROD && type !== 'designConfiguration' && configJson['requirement-number']) {
    console.info(`%c二开区域:`, 'color:#5cde9c');
    console.info(dom);
  }
  return newProps;
};

export default setAttributes;
